package boy.ui
{
   import flash.display.Bitmap;
   import flash.display.BitmapData;
   import flash.geom.Point;
   import flash.ui.Mouse;
   import flash.ui.MouseCursor;
   import flash.ui.MouseCursorData;
   
   /**
    * Runtime Versions: FlashPlayer 10.2
    * @author cjboy | cjboy1984@gmail.com
    * @usage
    import flash.ui.Mouse;
    import flash.ui.MouseCursor;
    import boy.ui.CursorManager_10_2;
   
    // init
    CursorManager_10_2.init();
    
    // show grab open
    Mouse.cursor = CursorPlusV2.GRAB_OPEN;
    // show grab closed
    Mouse.cursor = CursorPlusV2.GRAB_CLOSED;
    // return to normal
    Mouse.cursor = MouseCursor.AUTO;
    
    // destroy
    CursorPlusV2.destroy();
    */
   public class CursorPlusV2
   {
      [Embed(source="png/grab_closed.png")]
      private const BMPDATA_CLOSED:Class;
      [Embed(source="png/grab_open.png")]
      private const BMPDATA_OPEN:Class;
      
      // native
      public static const ARROW:String = MouseCursor.ARROW;
      public static const AUTO:String = MouseCursor.AUTO;
      public static const BUTTON:String = MouseCursor.BUTTON;
      public static const HAND:String = MouseCursor.HAND;
      public static const IBEAM:String = MouseCursor.IBEAM;
      
      // customize
      public static const GRAB_CLOSED:String = 'grab_closed';
      public static const GRAB_OPEN:String = 'grab_open';
      
      protected var inited:Boolean = false;
      
      // singleton
      protected static var _instance:CursorPlusV2;
      
      public function CursorPlusV2(pvt:PrivateClass)
      {
      }
      
      // --------------------- LINE ---------------------

      public static function get instance():CursorPlusV2
      {
         if (!_instance)
         {
            _instance = new CursorPlusV2(new PrivateClass());
            _instance.inited = false;
         }
         
         return _instance;
      }
      
      // --------------------- LINE ---------------------
      
      public static function init():void
      {
         if (instance.inited) return;

         instance._init();
      }
      
      // ################### protected ##################
      
      protected function _init():void
      {
         // [ grab closed ]
         var cursorData_1:MouseCursorData = new MouseCursorData();
         var bmpData_1:Vector.<BitmapData> = new Vector.<BitmapData>();
         var bmp_1:Bitmap = new BMPDATA_CLOSED();
         bmpData_1.push(bmp_1.bitmapData);
         cursorData_1.hotSpot = new Point(bmp_1.width >> 1, bmp_1.height >> 1);
         cursorData_1.data = bmpData_1;
         Mouse.registerCursor(GRAB_CLOSED, cursorData_1);
         
         // [grab open]
         var cursorData_2:MouseCursorData = new MouseCursorData();
         var bmpData_2:Vector.<BitmapData> = new Vector.<BitmapData>();
         var bmp_2:Bitmap = new BMPDATA_OPEN();
         bmpData_2.push(bmp_2.bitmapData);
         cursorData_2.hotSpot = new Point(bmp_2.width >> 1, bmp_2.height >> 1);
         cursorData_2.data = bmpData_2;
         Mouse.registerCursor(GRAB_OPEN, cursorData_2);
         
         instance.inited = true;
      }
      
      // #################### private ###################
      
      // --------------------- LINE ---------------------
      
   }
   
}

class PrivateClass
{
   public function PrivateClass()
   {
   }
}